import type { DynamicProps } from '/#/utils';
import type { BasicTableProps, BasicColumn } from '/@/components/Table/src/types/table';
import { FormProps } from '/@/components/Table';
import { searchSchemas } from './searchData';
import { getDeviceModeList } from '/@/api/sys/gateway/gateway';
import moment from 'moment';

type Props = Partial<DynamicProps<BasicTableProps>>;

// 列配置
const tableColumns: BasicColumn[] = [
  {
    title: '模型编码',
    dataIndex: 'id',
    fixed: 'left',
    width: 60,
  },
  {
    title: '模型名称',
    dataIndex: 'name',
    fixed: 'left',
    width: 130,
  },
  {
    title: '创建时间',
    dataIndex: 'create_time',
    width: 100,
    format: (text) => {
      return moment(parseInt(text) * 1000).format('YYYY-MM-DD HH:mm');
    },
  },
  {
    title: '修改时间',
    dataIndex: 'update_time',
    width: 80,
    format: (text) => {
      return moment(parseInt(text) * 1000).format('YYYY-MM-DD HH:mm');
    },
  },
];

export const formConfig: Partial<FormProps> = {
  labelWidth: 60,
  schemas: searchSchemas,
  actionColOptions: {
    span: 8,
    style: { textAlign: 'left', marginLeft: '40px' },
  },
};
export const tableConfig: Props = {
  api: getDeviceModeList,
  fetchSetting: {
    //配置数据data名称
    listField: 'list',
    totalField: 'total',
    sizeField: 'page_size',
  },
  columns: tableColumns,
  useSearchForm: true,
  formConfig: formConfig,
  showTableSetting: true,
  showIndexColumn: false,
  tableSetting: { fullScreen: true },
  bordered: true,
  actionColumn: {
    width: 80,
    title: '操作',
    slots: { customRender: 'action' },
  },
};
